package com.cy.pj.ajax.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {

    private List<String> list=new ArrayList<>(); //假设这是存储名字的数据库

    @RequestMapping("/doSave")
    public String doSave(String name){
        list.add(name);
        return "save ok";
    }

    @RequestMapping("/doCheck")
    public String doCheck(String name){
        return list.contains(name)?name+"已存在":"";
    }
    @CrossOrigin
    @RequestMapping("/doAjaxGet")
    public String doAjaxGet(){
        System.out.println("===doAjaxGet()===");
        return "Ajax Get Request Result";
    }

}
